package com.itheima.api.treeset.demo03;

import java.util.Comparator;
import java.util.TreeSet;

public class StudentDemo03 {

    public static void main(String[] args) {

        Student s1 = new Student("晓星尘", 23);
        Student s2 = new Student("宋子琛", 24);
        Student s3 = new Student("霜华", 17);
        Student s4 = new Student("拂雪", 17);

//        TreeSet<Student> treeSet = new TreeSet<Student>(new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                int i = o1.getAge() - o2.getAge();
//                int i1 = i == 0 ? o1.getName().compareTo(o2.getName()) : i;
//                return i1;
//            }
//        });

        TreeSet<Student> treeSet = new TreeSet<Student>((o1, o2) -> {
            int i = o1.getAge() - o2.getAge();
                int i1 = i == 0 ? o1.getName().compareTo(o2.getName()) : i;
                return i1;
        });

        treeSet.add(s1);
        treeSet.add(s2);
        treeSet.add(s3);
        treeSet.add(s4);

        treeSet.forEach( s -> System.out.println(s));

    }
}
